#include <stdio.h>
#define maxn 100006
int n, m;
int dir[maxn];
char name[maxn][12];
int a, s;
int cur = 0;
int main() {
  scanf("%d%d", &n, &m);
  for(int i=0; i<n; ++i) {
    scanf("%d%s", dir+i, name+i);
  }
  for(int i=0; i<m; ++i) {
    scanf("%d%d", &a, &s);
    if(dir[cur]==a)
        cur = (cur-s+n)%n;
    else cur = (cur+s)%n;
  }
  puts(name[cur]);
}

